# include <cstdio>
# include <cstring>
# include <iostream>
# include <algorithm>
# include <vector>
# include <map>

using namespace std;

# define testin freopen("in.txt", "r", stdin)
# define testout freopen("out.txt", "w", stdout)

# define rep(x) for(int i = 0; i < (x); ++i)
# define clr(x) memset(x, 0, sizeof(x))
# define clrc(x, c) memset(x, 0, (c)*sizeof(x[0]))

typedef unsigned long long int ulli;
typedef long long int lli;
const int destpos = 12;
const int dest = 0x873DF;
char b[7][7];
int st, stp;
vector<int> f[27];
const int dx[] = {1,1,2,2,-1,-1,-2,-2};
const int dy[] = {2,-2,1,-1,2,-2,1,-1};
bool success;
map<int, int> mp;
void dfs(int s, int depth)
{
    if (depth <= 0) return ;
    int cpos = s>>25;
    int cs = s & 0x1FFFFFF;
    rep(f[cpos].size()) {
        if (success) return ;
        int npo = f[cpos][i];
        int t = cs & (0x1<<npo);
        int nxx = t ? cs:(cs+(0x1<<npo)-(0x1<<cpos));
        int nst = nxx + (npo<<25);
        if (nst == (dest + (destpos << 25))) {
            success = true;
            return ;
        } else {
            dfs(nst, depth-1);
        }
    }
}
int main()
{
    testin;
    rep(5) for (int j = 0; j < 5; ++j)
    {
        int t = i*5+j;
        for (int k = 0; k < 8; ++k)
        {
            int ni = i + dx[k];
            int nj = j + dy[k];
            if (0<=ni&&ni<5&&0<=nj&&nj<5)
            {
                f[t].push_back(ni*5+nj);
            }
        }
    }

    int T;
    cin >> T;
    while (T--) {
        rep(5) scanf("%s", b[i]);
        st = 0;
        rep(5) for (int j = 0; j < 5; ++j) {
            int t = j+i*5;
            if (b[i][j]=='*' || b[i][j]=='1') {
                st |= (0x1<<(t));
                if (b[i][j] == '*') stp=t;
            }
        }
        int ans;
        success = false;
        if (((stp<<25)+st) == (dest + (destpos << 25)))
        {
            success = true;
        }
        for (ans = 0; !success && ans <= 12; ++ans) {
            success = false;
            dfs((stp<<25)+st, ans);
        }
        if(success) cout << ans <<endl;
        else cout << "Bored!" <<endl;
    }
    return 0;
}
